package itchen.com.inputdemo;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

	PswInputView view;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		view = (PswInputView) findViewById(R.id.psw_input);

		view.setInputCallBack(new PswInputView.InputCallBack() {
			@Override
			public void onInputFinish(String result) {
				Toast.makeText(MainActivity.this, result, Toast.LENGTH_SHORT).show();
				view.postDelayed(new Runnable() {
					@Override
					public void run() {
						view.clearResult();
					}
				}, 2000);
			}
		});

		//悬浮按钮的点击事件
		FloatingActionButton floatingActionButton = (FloatingActionButton) this.findViewById(R.id.fab_add_comment);
		floatingActionButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				//showTips();
				showTips2();
			}
		});

	}

	private void showTips2() {

		//AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MainActivity.this,R.style.AlertDialogTheme);
		AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MainActivity.this);
		dialogBuilder.setTitle("Warning");
		dialogBuilder.setMessage("You are forced to be offline. Please try to login again.");
		dialogBuilder.setCancelable(false);
		dialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {

				Intent intent = new Intent();
				intent.setClass(MainActivity.this,Main2Activity.class);
				startActivity(intent);

			}
		});

		//dialogBuilder.show();//第一种展示模式
		AlertDialog alertDialog = dialogBuilder.create();
		//alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
		alertDialog.show();

	}

	/*new DialogInterface.OnClickListener() {
		@Override
		public void onClick(DialogInterface dialog, int which) {
						*//*ActivityCollector.finishAll();
						Intent intent = new Intent(context, LoginActivity.class);
						intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
						context.startActivity(intent);*//*

			Toast.makeText(MainActivity.this, "测试代码", Toast.LENGTH_LONG).show();
		}
	}*/


	private void showTips() {

         /*
         这里使用了 android.support.v7.app.AlertDialog.Builder
         可以直接在头部写 import android.support.v7.app.AlertDialog
         那么下面就可以写成 AlertDialog.Builder
         */
		android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(this);
		builder.setTitle("提示内容");
		builder.setMessage("这是展示样式内容,请仔细查看");
		builder.setNegativeButton("取消", null);
		builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				Toast.makeText(MainActivity.this, "测试代码", Toast.LENGTH_LONG).show();
			}
		});
		builder.show();


	}

}
